//
//  WMWebViewController.m
//  witMorning
//
//  Created by Mac mini on 2018/1/4.
//  Copyright © 2018年 zt. All rights reserved.
//

#import "WMWebViewController.h"

@interface WMWebViewController ()
@end

@implementation WMWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
}

-(void)loadHTML{
    if (!_webView) {
        _webView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
        
        _webView.UIDelegate = self;
        _webView.navigationDelegate = self;
        [self.view addSubview:_webView];
       }
    
    [MBProgressHUD showHUDAddedTo:self.view  animated:YES];
    
    if (self.localHtml) {
        NSString *webViewSoruce = @"";
        NSLog(@"%@",self.localHtml);
        webViewSoruce  = (__bridge_transfer NSString *)CFURLCreateStringByReplacingPercentEscapes(NULL, (__bridge CFStringRef)self.localHtml, CFSTR(""));
        
        [_webView loadHTMLString:webViewSoruce baseURL:nil];
    }else{
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:_netHtml]];
        [self.webView loadRequest:request];
    }

}

-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    if (self.localHtml) {
         [webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '200%'" completionHandler:nil];
    }else{
         [webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '150%'" completionHandler:nil];
    }
   
    [MBProgressHUD hideHUDForView:self.view animated:YES];

}

-(void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error{
    [MBProgressHUD hideHUDForView:self.view animated:YES];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
